import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '../'))
import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.api as sm
from  utils import column_letter_to_index

data_path = '../../data/raw_data/334份 按选项序号 汇总变量后.xlsx'

df = pd.read_excel(data_path)  

y_index_list = [column_letter_to_index(each) for each in ['AT','CG','CH','CI']]
# print('drop 之前')

#先找到因变量
df_y = df[df.columns[y_index_list]]
# 去除自变量
df_x = df.drop(df.columns[y_index_list], axis=1) # 自变量
# 去除第一列
df = df.drop(df.columns[0], axis=1)


for i in range(df_y.shape[1]):
    print('--------------{}--------------'.format(df_y.columns[i]))
    this_y = df_y.iloc[:,i]
    this_x = sm.add_constant(df_x)
    model = sm.OLS(this_y, this_x).fit()
    print(model.summary())
    # print(this_y.info())

# y = df['Y']  # 因变量

# # 为模型添加常数项，这是多数回归分析所需要的
# X = sm.add_constant(X)

# # 创建一个OLS模型
# model = sm.OLS(y, X).fit()

# # 打印出回归结果
# print(model.summary())